import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export interface AudioParams {
  audioUrl: string
}
export const useUnityRoleStore = defineStore('unityRole', () => {
  /**
   * Unity角色id
   * */
  // 创建一个引用，用于存储当前Unity角色ID
  const currentUnityRoleId = ref('006')

  // 计算属性，获取当前Unity角色ID的值
  const getCurrentUnityRoleId = computed(() => currentUnityRoleId.value)

  // 更新当前Unity角色ID
  const updateCurrentUnityRoleId = (id: string) => {
    currentUnityRoleId.value = id
  }

  /**
   *Unity加载状态
   * */
  // unity角色是否加载完毕
  const isUnityRoleLoadFinish = ref(false)
  const setIsUnityRoleLoadFinish = (finish: boolean) => {
    isUnityRoleLoadFinish.value = finish
  }
  const getIsUnityRoleLoadFinish = computed(() => isUnityRoleLoadFinish.value)

  /**
   * Unity角色发声
   * */
  // unity角色是否可以发声
  const isUnityRoleTalk = ref(true)
  const setIsUnityRoleTalk = (talk: boolean) => {
    isUnityRoleTalk.value = talk
  }
  const getIsUnityRoleTalk = computed(() => isUnityRoleTalk.value)
  // unity角色发声函数
  let unityRoleTalk = (param: AudioParams) => {
    console.log('unityRoleTalk', param)
  }
  const setUnityRoleTalk = (talk: (param: AudioParams) => void) => {
    unityRoleTalk = talk
  }
  const getUnityRoleTalk = computed(() => {
    if (!isUnityRoleTalk.value) return () => {}
    return unityRoleTalk
  })

  return {
    getCurrentUnityRoleId,
    updateCurrentUnityRoleId,
    setIsUnityRoleLoadFinish,
    getIsUnityRoleLoadFinish,
    setUnityRoleTalk,
    setIsUnityRoleTalk,
    getIsUnityRoleTalk,
    getUnityRoleTalk
  }
})
